<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>输出字符串</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.print" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">print</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">print</span> &mdash; <span class="dc-title">输出字符串</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.print-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>print</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$arg</code></span>
   ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   输出 <code class="parameter">arg</code>。
  </p>
  <p class="para">
   <span class="function"><strong>print</strong></span> 实际上不是函数（而是语言结构），所以可以不用圆括号包围参数列表。
  </p>
  <p class="para">
   和 <em>echo</em> 最主要的区别：
   <em>print</em> 仅支持一个参数，并总是返回 1。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.print-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">arg</code></dt>

     <dd>

      <p class="para">
       输入数据。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.print-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   总是返回 <em>1</em>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.print-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5933">
    <p><strong>Example #1 <span class="function"><strong>print</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">print(</span><span style="color: #DD0000">"Hello&nbsp;World"</span><span style="color: #007700">);<br /><br />print&nbsp;</span><span style="color: #DD0000">"print()&nbsp;also&nbsp;works&nbsp;without&nbsp;parentheses."</span><span style="color: #007700">;<br /><br />print&nbsp;</span><span style="color: #DD0000">"This&nbsp;spans<br />multiple&nbsp;lines.&nbsp;The&nbsp;newlines&nbsp;will&nbsp;be<br />output&nbsp;as&nbsp;well"</span><span style="color: #007700">;<br /><br />print&nbsp;</span><span style="color: #DD0000">"This&nbsp;spans\nmultiple&nbsp;lines.&nbsp;The&nbsp;newlines&nbsp;will&nbsp;be\noutput&nbsp;as&nbsp;well."</span><span style="color: #007700">;<br /><br />print&nbsp;</span><span style="color: #DD0000">"escaping&nbsp;characters&nbsp;is&nbsp;done&nbsp;\"Like&nbsp;this\"."</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;可以在打印语句中使用变量<br /></span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"foobar"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"barbaz"</span><span style="color: #007700">;<br /><br />print&nbsp;</span><span style="color: #DD0000">"foo&nbsp;is&nbsp;</span><span style="color: #0000BB">$foo</span><span style="color: #DD0000">"</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;foo&nbsp;is&nbsp;foobar<br /><br />//&nbsp;也可以使用数组<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"value"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">);<br /><br />print&nbsp;</span><span style="color: #DD0000">"this&nbsp;is&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$bar</span><span style="color: #007700">[</span><span style="color: #DD0000">'value'</span><span style="color: #007700">]}</span><span style="color: #DD0000">&nbsp;!"</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;this&nbsp;is&nbsp;foo&nbsp;!<br /><br />//&nbsp;使用单引号将打印变量名，而不是变量的值<br /></span><span style="color: #007700">print&nbsp;</span><span style="color: #DD0000">'foo&nbsp;is&nbsp;$foo'</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;foo&nbsp;is&nbsp;$foo<br /><br />//&nbsp;如果没有使用任何其他字符，可以仅打印变量<br /></span><span style="color: #007700">print&nbsp;</span><span style="color: #0000BB">$foo</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;foobar<br /><br /></span><span style="color: #007700">print&nbsp;&lt;&lt;&lt;END<br /></span><span style="color: #DD0000">This&nbsp;uses&nbsp;the&nbsp;"here&nbsp;document"&nbsp;syntax&nbsp;to&nbsp;output<br />multiple&nbsp;lines&nbsp;with&nbsp;</span><span style="color: #0000BB">$variable</span><span style="color: #DD0000">&nbsp;interpolation.&nbsp;Note<br />that&nbsp;the&nbsp;here&nbsp;document&nbsp;terminator&nbsp;must&nbsp;appear&nbsp;on&nbsp;a<br />line&nbsp;with&nbsp;just&nbsp;a&nbsp;semicolon&nbsp;no&nbsp;extra&nbsp;whitespace!<br /></span><span style="color: #007700">END;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.print-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">因为是一个语言构造器而不是一个函数，不能被
<a href="functions.variable_functions.html" class="link">可变函数</a> 调用。
</span>
</p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.print-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="echo.html" class="function" rel="rdfs-seeAlso">echo</a> - 输出一个或多个字符串</span></li>
    <li class="member"><span class="function"><a href="printf.html" class="function" rel="rdfs-seeAlso">printf()</a> - 输出格式化字符串</span></li>
    <li class="member"><span class="function"><a href="flush.html" class="function" rel="rdfs-seeAlso">flush()</a> - 刷新输出缓冲</span></li>
    <li class="member"><a href="language.types.string.html#language.types.string.syntax.heredoc" class="link">Heredoc syntax</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>